﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMSSys
{
    public partial class Login : Form
    {
        private DBconnentor dbProcessor;

        public DBconnentor DbProcessor
        {
            get { return dbProcessor; }
        }
        public Login()
        {
            InitializeComponent();
            dbProcessor = new DBconnentor();
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            if (usernameBox.Text != String.Empty)
            {
                if (passwordBox.Text != String.Empty)
                {
                    if (dbProcessor.OpenConnection("pms", textBox3.Text, usernameBox.Text, passwordBox.Text, textBox4.Text))
                    {
                        PatientsListView newWindow = new PatientsListView(this);
                        newWindow.Show();
                    }
                }
                else
                    MessageBox.Show("Password cannot be blank", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
            } 
            else
                MessageBox.Show("Username cannot be blank", "Username", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void defaultConnection_CheckedChanged(object sender, EventArgs e)
        {
            groupBox1.Enabled = advancedConnection.Checked;
            if(defaultConnection.Checked)
            {
                textBox3.Text = "localhost";
                textBox4.Text = "3306";
            }
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Login_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (dbProcessor.getConnection() != null)
                dbProcessor.closeConnection();
        }
        private void Login_Load(object sender, EventArgs e)
        {
            ToolTip t1 = uiUtility.tooltips();
            t1.SetToolTip(this.loginButton, "Log In");
            t1.SetToolTip(this.exitButton, "Exit");
        }
    }
}
